// pages/withdraw/withdraw.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    withdrawList: [{
        amount: '+289',
        time: '12-01 17:12',
      },
      {
        amount: '+2469',
        time: '12-01 17:12',
      },
      {
        amount: '+229',
        time: '12-01 17:12',
      },
      {
        amount: '+29',
        time: '12-01 17:12',
      }
    ],
    account:""
  },
  // 查询钱包
  money: function() {
    var that = this;
    wx.request({
      url: 'https://www.xiaozheng8.com/money/record/findAll',
      data: {
        userId: wx.getStorageSync("userId")
      },
      method: 'post',
      success: function(res) {
        console.log(res);
        that.setData({
          withdrawList: res.data.data.record
        });
        // var price = 0;
        // for (var i = 0; i < that.data.withdrawList.length; i++) {
        //   price = price + that.data.withdrawList[i].money
        // };
        that.setData({
          total: res.data.data.ketixian,
          shouru: res.data.data.shouru,
          yitixian: res.data.data.yitixian,
        })
      },
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  // 金额详情
  detail:function(){
    wx.navigateTo({
      url: '../withdrawDetail/withdrawDetail',
    })
  },
//  获取提现金额
  inputChange:function(e){
    var  that=this;
    this.setData({
      account:e.detail.value
    });
    if(that.data.account>that.data.total){
      wx.showToast({
        title: '超出提现金额',
        icon:"none",
        duration:2000,
      })
    }
    console.log(this.data.account);
  },
  // 弹窗事件

// 提现版本1手动弹窗版
  // showDialogBtn: function () {



  //   this.setData({

  //     showModal: true

  //   })

  // },
// 提现版本2 跳转版
  showDialogBtn:function(){
    var that=this;
    wx.navigateTo({
      url: '../withdrawPage/withdrawPage?total='+that.data.total,
    })
  },
  /**
   
  * 弹出框蒙层截断touchmove事件
   
  */

  preventTouchMove: function () {

  },

  /**
   
  * 隐藏模态对话框
   
  */

  hideModal: function () {

    this.setData({

      showModal: false

    });

  },

  /**
   
  * 对话框取消按钮点击事件
   
  */

  onCancel: function () {

    this.hideModal();

  },

// 对话框确认按钮点击事件


  onConfirm: function () {
    var that=this;
    parseInt(that.data.account)
    if(that.data.account>that.data.total){
      wx.showToast({
        title:"超出提现金额",
        icon:"none",
        duration:2000
      })
    }else{
      wx.request({
        url: 'https://www.xiaozheng8.com/money/record/out',
        data: {
          userId:wx.getStorageSync("userId"),
          money:-that.data.account
        },
        method: 'post',
        success: function(res) {
          wx.showToast({
            title: '提现请求已提交',
            icon:"success",
            duration:2000
          });
          that.money();
        },
        fail: function(res) {},
        complete: function(res) {},
      })
    }
   

    this.hideModal();


  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.money();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})